import instance from "@/utils/axios.js";
import { getToken } from "@/utils/token.js";

function userLogin({ mobile, code }) {
  return instance({
    url: "/v1_0/authorizations",
    method: "POST",
    data: { mobile, code }
  });
}

export { userLogin };

// 获取用户个人资料
function getUserInfo() {
  return instance({
    url: "/v1_0/user/profile",
    method: "get",
    headers: {
      Authorization: `Bearer ${getToken().token}`
    }
  });
}

export { getUserInfo };

// 修改资料
function editUserInfo(data) {
  return instance({
    url: "/v1_0/user/profile",
    method: "patch",
    data,
    headers: {
      Authorization: `Bearer ${getToken().token}`
    }
  });
}

export { editUserInfo };

// 修改用户图片
function editAvatar(fd) {
  return instance({
    url: "/v1_0/user/photo",
    method: "patch",
    data: fd,
    headers: {
      Authorization: `Bearer ${getToken().token}`
    }
  });
}

export { editAvatar };
